/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.tesam.gedeon.controller;

/**
 *
 * @author Sistema
 */
import java.security.Key; 
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
public class Secret {
 	public  String getHmacMD5(String privateKey, String input, String algorithm) throws Exception{
		 byte[] keyBytes = privateKey.getBytes();
                 
		Key key = new SecretKeySpec(keyBytes, 0, keyBytes.length, algorithm); 
                Mac mac = Mac.getInstance(algorithm);//
//                return algorithm;
		mac.init(key); 
		return byteArrayToHex(mac.doFinal(input.getBytes()));
	}
	public  String byteArrayToHex(byte [] a) {
		int hn, ln, cx;
		String hexDigitChars = "0123456789abcdef";
		StringBuilder buf = new StringBuilder(a.length * 2);
		for(cx = 0; cx < a.length; cx++) {
			hn = ((int)(a[cx]) & 0x00ff) / 16;
			ln = ((int)(a[cx]) & 0x000f);
			buf.append(hexDigitChars.charAt(hn));
			buf.append(hexDigitChars.charAt(ln));
		}
		return buf.toString();
	}   
}
